﻿using MediatR;
using RBAC.MaHaiBo.API.Application.Command.FarmCommand;
using RBAC.MaHaiBo.Entity.Traceability;
using RBAC.MaHaiBo.Service.TraceabilityService;

namespace RBAC.MaHaiBo.API.Application.CommandHandlers.FarmHandler
{
    public class AddFarmCommandHandler:IRequestHandler<AddFarmCommand,int>
    {
        /// <summary>
        /// 养殖服务层
        /// </summary>
        IFarmService FarmS;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="FarmS">养殖服务层</param>
        public AddFarmCommandHandler(IFarmService FarmS)
        {
            this.FarmS = FarmS;
        }

        public async Task<int> Handle(AddFarmCommand request, CancellationToken cancellationToken)
        {
            return await FarmS.AddFarm(new Entity.Traceability.Farm() { farmid= request.farmid, variety = request.variety, Feedingdays = request.Feedingdays, FeedingName = request.FeedingName, Source = request.Source, Feedbrand = request.Feedbrand, Publicationdate = request.Publicationdate, LOT = request.LOT, Uid = request.Uid, AddName = request.AddName, AddTime = request.AddTime, UpdName = request.UpdName, UpdTime = request.UpdTime, DelName = request.DelName, DelTime = request.DelTime });
        }
    }
}
